package net.itheima.mm.controller;

import lombok.extern.slf4j.Slf4j;
import net.itheima.mm.entity.PageResult;
import net.itheima.mm.entity.QueryPageBean;
import net.itheima.mm.entity.Result;
import net.itheima.mm.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/catalog")
@Slf4j
public class CatalogController {
    @Autowired
    private CatalogService catalogService;

    @RequestMapping("/findListByPage")
    public Result findListByPage(@RequestBody QueryPageBean queryPageBean){
        queryPageBean.setOffset(queryPageBean.getOffset());
        List<net.itheima.mm.pojo.Catalog> catalogList=catalogService.findListByPage(queryPageBean);
        Long total= catalogService.findTatolListByPage(queryPageBean);
        PageResult pageResult=new PageResult(total,catalogList);
        log.info("[cataloglist数据:]data{}",catalogList);
        return new Result(true,"获取学科目录页表成功",pageResult);
    }
}
